package com.jingjiu.homeservicesbiz.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingjiu.homeservicesapi.domain.ForumComment;
import com.jingjiu.homeservicesapi.domain.ForumPost;
import com.jingjiu.homeservicesbiz.mapper.ForumCommentMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
*功能：
 作者：chenhao
*日期： 2025/4/21 下午1:57
*/
@Service
public class ForumCommentServiceImpl extends ServiceImpl<ForumCommentMapper, ForumComment> {

    @Autowired
    private ForumCommentMapper forumCommentMapper;
    @Autowired
    private ForumPostServiceImpl forumPostService;
//    public Page<ForumComment> selectPage(Page<ForumComment> page, ForumComment forumComment) {
//        LambdaQueryWrapper<ForumComment> queryWrapper = new LambdaQueryWrapper<>();
//        return this.page(page, queryWrapper);
//    }
    public List<ForumComment> selectForumCommentList(ForumComment forumComment) {
        return forumCommentMapper.selectForumCommentList(forumComment);
    }

    /**
     * 插入论坛评论
     *
     * @param forumComment 论坛评论
     * @return int
     */
    public int insertForumComment(ForumComment forumComment) {
        //根据评论获取帖子
        ForumPost forumPost = forumPostService.selectForumPostById(forumComment.getPostId());
        //把帖子评论数量+1
        forumPost.setCommentCount(forumPost.getCommentCount()+1);
        //重新存入帖子表
        forumPostService.updateById(forumPost);
        return forumCommentMapper.insertForumComment(forumComment);
    }
    public ForumComment selectForumCommentById(Long id) {
        return forumCommentMapper.selectForumCommentById(id);
    }

    public int updateForumComment(ForumComment forumComment) {

       return forumCommentMapper.updateForumComment(forumComment);
    }


    public int deleteForumCommentById(Long id) {
        return forumCommentMapper.deleteForumCommentById(id);
    }


}
